import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    loadingFlag:false,
    routerArr:[],
    /* 此操作为左侧边栏点击添加tab栏 */
    /* 当前活跃地址改变 */
    activePath:'',
    /* 活动tab页 */
    openTab:[],
  },
  mutations: {
    changeLoadingFlag(state,val){
      state.loadingFlag = val
    },
    addRouter(state,val){
      state.routerArr.push(val)
    },
    getRouter(state,val){
      state.routerArr = val
    },
    /* 当前活跃地址改变 */
    changeActivePath(state,path){
        sessionStorage.setItem("activePath",path),
        state.activePath = path
    },
    /* 添加tabs页 */
    add_tabs(state,data){
        let openTab = JSON.parse(sessionStorage.getItem("openTab")) || [];
        if(openTab.length < 1){
            openTab.push(data)
        } else if( openTab.length >=1 && openTab.length < 8 ){
            let flag = openTab.every(item=>item.path != data.path);
            if(flag) {
                openTab.push(data)
            }
        }else{
            let flag = openTab.every(item=>item.path != data.path);
            if(flag){
                openTab.splice(1,1)
                openTab.push(data)
            }
        }
        sessionStorage.setItem("openTab",JSON.stringify(openTab))
        state.openTab = openTab
    },
    /* 删除tab页 */
    delete_tabs(state,route){
        let index = 0
        state.openTab.forEach((item,i)=>{
            if(item.path == route){
                index = i
            }
        })
        state.openTab.splice(index,1)
        sessionStorage.setItem('openTab',JSON.stringify(state.openTab))
    }
  },
  actions: {
    async changeRouter({ commit }) {
      // const { data: { bizContent } }= await this.$axios.get('xx');
      // commit('getRouter',bizContent)
      let Routes = [
                {
                    id:0,
                    value:"/home",
                    name:'经营大数据',
                    type:'menu',
                    icon:'icon-wulianwang-'
                },
                {
                    id:1,
                    value:null,
                    name:'商品管理',
                    type:'menu',
                    icon:"icon-shangpinguanli",
                    children:[
                        {
                            id:7,
                            value:'/shopClass',
                            name:'商品分类',
                            type:'menu'
                        },
                        {
                            id:8,
                            value:'/shopDisc',
                            name:'折扣商品',
                            type:'menu'
                        },
                        {
                            id:9,
                            value:'/onOffShopaddShop',
                            name:'上下架商品',
                            type:'menu'
                        }
                    ]
                },
                {
                    id:2,
                    value:null,
                    name:'会员管理',
                    type:'menu',
                    icon:'icon-huiyuanguanli',
                    children:[
                        {
                            id:10,
                            value:'/members',
                            name:'普通会员',
                            type:'menu'
                        },
                        {
                            id:11,
                            value:'/HeaderManage',
                            name:'团长管理',
                            type:'menu'
                        },
                        {
                            id:12,
                            value:'/commitManage',
                            name:'班委管理',
                            type:'menu'
                        }
                    ]
                },
                {
                    id:3,
                    value:null,
                    name:'订单管理',
                    type:'menu',
                    icon:'icon-dingdanguanli',
                    children:[
                        {
                            id:13,
                            value:'/customOrder',
                            name:'客户订单列表',
                            type:'menu'
                        },
                        {
                            id:14,
                            value:'/customRefund',
                            name:'客户退款列表',
                            type:'menu'
                        },
                        {
                            id:15,
                            value:'/orderPlat',
                            name:'订单列表(平台)',
                            type:'menu'
                        },
                        {
                            id:16,
                            value:'/orderHeader',
                            name:'订单列表(团长)',
                            type:'menu'
                        }
                    ]
                },
                {
                    id:4,
                    value:null,
                    name:'营销中心',
                    type:'menu',
                    icon:'icon-yingxiaozhongxin',
                    children:[
                        {
                            id:17,
                            value:'/marketList',
                            name:'营销列表',
                            type:'menu'
                        },
                        {
                            id:18,
                            value:'/galleryList',
                            name:'展厅列表',
                            type:'menu'
                        },
                        {
                            id:19,
                            value:'/noGalleryList',
                            name:'非展厅列表',
                            type:'menu'
                        }
                    ]
                },
                {
                    id:5,
                    value:null,
                    name:'数据中心',
                    type:'menu',
                    icon:'icon-liuliangyunpingtaitubiao06',
                    children:[
                        {
                            id:20,
                            value:'/dataList',
                            name:'数据列表',
                            type:'menu'
                        },
                        {
                            id:21,
                            value:'/cadreScale',
                            name:'干部规模',
                            type:'menu'
                        },
                        {
                            id:22,
                            value:'/earnData',
                            name:'收益数据',
                            type:'menu'
                        }
                    ]
                },
                {
                    id:6,
                    value:null,
                    name:'系统配置',
                    type:'menu',
                    icon:'icon-shangpinguanli',
                    children:[
                        {
                            id:23,
                            value:'/fenceConfig',
                            name:'围栏配置',
                            type:'menu'
                        },
                        {
                            id:24,
                            value:'/smsConfig',
                            name:'短信平台配置',
                            type:'menu'
                        },
                        {
                            id:25,
                            value:'/serverConfig',
                            name:'服务器配置',
                            type:'menu'
                        }
                    ]
                }
            ]
      commit('getRouter',Routes);
    },

  }
})
